<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>我的购物车</title>
    <link rel="stylesheet" type="text/css" href="/Public/Home/styles/shoppingcart.css"/>
    <script src="/Public/Home/js/jquery-1.11.0.js"  type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="outside">
    <br>
        <div id="inside">
            <div class="logo"><img src="/Public/Home/images/third-logo.png" alt=""/></div>
            <div class="logo"><h1>&nbsp;&nbsp;我的购物车</h1></div>
            <div class="logo" id="span1"><span>&nbsp;&nbsp;温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</span></div>
            <div id="right-top">
                <span>
                <empty name="Think.session.id">
                    <a href="{:U('Index:login')}">登录</a>
                    <span class="second-floor-menu-span">|</span>
                    <a href="{:U('Index:register')}">注册</a>
                    <else />
                    <a href="#">{$user}，您好！</a>
                </empty>| <a href="{:U('Index:myorder')}">我的订单</a>
                </span>
            </div>
        </div>
    <hr>
</div>
<div id="outContent">
    <form action="{:U('/Index/confirm_order')}" method="post">
    <div id="content">
        <table>
            <tr>
                <th class="td1">选择</th>
                <th class="td2">商品名称</th>
                <th class="td1">单价</th>
                <th class="td1">数量</th>
                <th class="td1">小计</th>
                <th class="td1">操作</th>
            </tr>
            <foreach name="data" item="vo" key="k" >
                <tr id="{$vo.id}">
                    <td class="td1">
                        <input name="goods[]" onclick="fun1({$vo.xiaoji},{$vo.id})" type="checkbox" value="{$vo.goodsinformation}×{$vo.number}" />
                    </td>
                    <td class="td2">{$vo.goodsinformation}</td>
                    <td class="td1">{$vo.price}</td>
                    <td class="td1">{$vo.number}</td>
                    <td class="td1">{$vo.xiaoji}</td>
                    <td class="td1"><a class="a" onclick="fun({$vo.id})">×</a></td>
                </tr>
            </foreach>
        </table>
    </div>
    <br>
    <br>
    <div id="bottom">
        <div id="bottom-left">继续购物 共 <span id="count">{$count}</span> 件商品，已选择 <span id="number">0</span> 件</div>
        <div id="bottom-right"><span>合计（不含运费）:<b id="total1">0</b>元</span><button type="submit">去结算</button></div>
        <input type="text" style="display: none" id="total" name="total" value="0">
        <input type="text" style="display: none" id="checkedGoodsID" name="checkedGoodsID" value="">
    </div>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    function fun(value) {
        var request = new XMLHttpRequest();
        url='/Index/shoppingcart_action';
        request.open("post", url, "true");
        request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        request.send( 'id='+value );
        request.onreadystatechange = function () {
            if (request.readyState == 4) {
                if (request.status == 200) {
                    if(request.responseText!='0') {
                        $("#" + value).remove();
                        //$('#count').innerHTML-=1;
                        var html=$('#count').html();
                        document.getElementById("count").innerHTML=html-1;
                    }
                }
            }
        }
    }
    function fun1(i,j){
        var c=event.target.checked;
        var html=document.getElementById('number').innerHTML;
        var total=parseInt(document.getElementById('total1').innerHTML);
        var str=document.getElementById('checkedGoodsID').value;
        if(c==true) {
            total+=i;
            html++;
            if(str=='')
                str=j;
            else
                 str=str+','+j;
        }else if(c==false) {
            var strs=str.split(",");
            str='';
            for(k=0;k<strs.length;k++) {
                if(strs[k]==j)
                    continue;
                if(str=='')
                    str=strs[k];
                else
                    str=str+','+strs[k];
            }
            html--;
            total-=i;
        }
        document.getElementById('number').innerHTML=html;
        document.getElementById('total1').innerHTML=total;
        document.getElementById('total').value=total;
        document.getElementById('checkedGoodsID').value=str;
    }

</script>